import html from '../../assets/partials/channel-list.html';
import './channel-mng';
import './channel-edit';

export default {
    name: 'channelList',
    title: '频道管理',
    html: html,
    beforeMount: element => {
        console.info('马上要显示了');
    },
    mounted: (element, menudata) => {
        console.info('已经显示出来');

        element.find(".check-all").click(function() {
            if ($(this).is(':checked')) {
                element.find("input:checkbox").attr("checked", true);
            } else {
                element.find("input:checkbox").attr("checked", false);
            }
        });

        element.find('table').dataTable({
            "dom": 'rt<"clearfix table-bottom"ilp>',
            "searching": false,
            "ordering": false,
            "serverSide": true,
            "processing": true,
            "scrollX": true,
            "language": {
                'emptyTable': '当前暂无数据',
                'info': '第 _PAGE_ 页 / 总 _PAGES_ 页，',
                'infoEmpty': '',
                'lengthMenu': '每页 _MENU_ ',
                "paginate": {
                    "first": "第一页",
                    "last": "最后一页",
                    "next": "下一页",
                    "previous": "上一页"
                }
            },
            "pagingType": "full_numbers",
            "columns": [{
                    "className": "text-center",
                    "render": function(data, type, row) {
                        return '<input type="checkbox" name="" value="' + row.groupId + '">';
                    }
                }, {
                    "data": "groupName"
                },
                {
                    "render": function(data, type, row) {
                        var className = "label-success";
                        switch (row.status) {
                            case "CONF_FAIL":
                                className = "label-danger";
                                break;
                            case "RUNNING":
                                className = "label-primary";
                                break;
                            case "NOT_SYNC":
                                className = "label-default";
                                break;
                        }
                        return '<span class="label ' + className + ' radius">' + row.statusDesc + '</span>';
                    }
                },
                {
                    "data": "lastConfTime"
                },
                {
                    "data": "createTime"
                },
                {
                    "data": "updateTime"
                },
                {
                    'className': 'text-c',
                    "render": function(data, type, row) {
                        var $div = $("<div class='table-btn'>");
                        $div.append($("<i class='icon icon-inlineEdit' onclick='$.editChannel(" + row.groupId + ")'>"));
                        $div.append($("<i class='icon icon-download' onclick='$.confChannel(" + row.groupId + ")'>"));
                        $div.append($("<i class='icon icon-del' onclick='$.delChannel(" + row.groupId + ")'>"));
                        return $div.html();
                    }
                }
            ],
            "ajax": function(data, callback, settings) {
                var pageSize = data.length;
                var page = data.start / pageSize + 1;
                data.pageSize = pageSize;
                data.page = page;
                $.myAjax({
                    url: "channel/getChannelList.do",
                    dataType: "json",
                    contentType: "application/json",
                    data: JSON.stringify(data),
                    success: function(result) {
                        result.recordsTotal = result.total;
                        result.recordsFiltered = result.total;
                        return callback(result);
                    }
                });
            }
        });
    },
    unmounted: element => {
        console.info('不显示了');
    }
};
